package com.zhhh.domain;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.zhhh.utils.CodeUtil;

public class MenuNode {
	private String id;

	private String title;

	private String ico;

	private String link;

	private String model;

	private String width;

	private String height;

	private String hasChilds;
	
	private Integer pid;
	
	private Integer mid;
	
	private String modeCode;

	private List<MenuNode> childs;

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return this.id;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return this.title;
	}

	public void setIco(String ico) {
		this.ico = ico;
	}

	public String getIco() {
		return this.ico;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getLink() {
		return this.link;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getModel() {
		return this.model;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public String getWidth() {
		return this.width;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public String getHeight() {
		return this.height;
	}

	public void setHasChilds(String hasChilds) {
		this.hasChilds = hasChilds;
	}

	public String getHasChilds() {
		return this.hasChilds;
	}

	public void setChilds(List<MenuNode> childs) {
		this.childs = childs;
	}

	public List<MenuNode> getChilds() {
		return this.childs;
	}

	public static MenuNode getMenuTreeNode(List<BMenuTree> menuTrees,MenuNode parentNode,Set<BMode> modes) {
		List<MenuNode> treeRootNodeList = new ArrayList<MenuNode>();
		for (BMenuTree menuNode : menuTrees) {
			if(menuNode.getPId()==parentNode.getMid()) {
				for (BMode bMode : modes) {
					if(menuNode.getSModeId().equals(bMode.getId().toString())) {
						MenuNode menutreeNode = new MenuNode();
						String id = CodeUtil.createUUID();
						menutreeNode.setId(id);
						menutreeNode.setModeCode(bMode.getModeCode());
						menutreeNode.setTitle(menuNode.getMenuDesc());
						menutreeNode.setIco("");
						menutreeNode.setLink(bMode.getUrl());
						menutreeNode.setModel("0");
						menutreeNode.setWidth("");
						menutreeNode.setHeight("");
						menutreeNode.setPid(menuNode.getPId());
						menutreeNode.setMid(menuNode.getId());
						treeRootNodeList.add(menutreeNode);
					}
				}
			}
		}
		
		if(treeRootNodeList.size()>0) {
			for (int i = 0; i < treeRootNodeList.size(); i++) {
				getMenuTreeNode(menuTrees,treeRootNodeList.get(i),modes);
			}
		}
		parentNode.setChilds(treeRootNodeList);
		return parentNode;
	}

	public Integer getPid() {
		return pid;
	}

	public void setPid(Integer pid) {
		this.pid = pid;
	}

	public Integer getMid() {
		return mid;
	}

	public void setMid(Integer mid) {
		this.mid = mid;
	}

	public String getModeCode() {
		return modeCode;
	}

	public void setModeCode(String modeCode) {
		this.modeCode = modeCode;
	}

}